﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Smart
{
    /// <summary>
    /// 消息传递接口
    /// </summary>
    public interface IMessageInfo
    {
        /// <summary>
        /// 消息状态
        /// </summary>
        int Status { get; set; }
        /// <summary>
        /// 消息内容添加
        /// </summary>
        /// <param name="msg"></param>
        void Add(string msg);
        /// <summary>
        /// 消息内容清空
        /// </summary>
        void Clear();
    }

    /// <summary>
    /// 消息对象
    /// 默认使用换行回车符号合并新行
    /// </summary>
    public class MessageInfo : IMessageInfo
    {
        public MessageInfo()
        {
            ///默认使用换行回车符号合并新行
            JoinToken = Environment.NewLine;
        }

        /// <summary>
        /// 内部消息列表
        /// </summary>
        protected List<string> msgList = new List<string>();

        /// <summary>
        /// 消息状态 默认为0 
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 消息合并符号
        /// </summary>
        public string JoinToken { get; set; }

        /// <summary>
        /// 添加消息内容
        /// </summary>
        /// <param name="msg"></param>
        public void Add(string msg)
        {
            msgList.Add(msg);
        }

        /// <summary>
        /// 输出消息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Join(JoinToken, msgList.ToArray());
        }

        /// <summary>
        /// 清空消息内容
        /// </summary>
        public void Clear()
        {
            msgList.Clear();
        }
    }
}
